/*********************************************************
          File Name:10.18_19.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Fri 26 Feb 2016 08:22:30 PM CST
**********************************************************/

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void biggies(vector<string> &words, vector<string>::size_type sz, bool stable = false)
{
    sort(words.begin(), words.end());
    words.erase(unique(words.begin(), words.end()), words.end());
    stable_sort(words.begin(), words.end());
    vector<string>::iterator wc;
    auto lambda = [sz](const string &s) -> bool { return s.size() >= sz; };
    // partition will modify container 
    if(!stable)
        wc = partition(words.begin(), words.end(), lambda);
    else
        wc = stable_partition(words.begin(), words.end(), lambda);
    cout << wc - words.begin() << " word(s) of length " << sz << " or longer\n";
    for_each(words.begin(), wc, 
            [](const string &s) {
                cout << s << " ";
            });
    cout << endl;
}

int main()
{
    vector<string> vs{"the", "blue", "firefox", "jump", "over", "blue", "dog"};
    vector<string> vs2(vs.begin(), vs.end());
    cout << "10.18:\n";
    biggies(vs, 4);
    cout << "10.19:\n";
    biggies(vs, 4, true);
    return 0;
}
